package jpb.util.load.excel;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 * Created by haol on 2017/5/13.
 */
public class ExcelRow {
        private ExcelCellStyle cellStyle;
        public ExcelRow(HSSFWorkbook workbook){
                cellStyle = new ExcelCellStyle(workbook);
        }


        public HSSFSheet createRowHead(HSSFSheet hssfSheet, String[] head,int row){
//                SetValidation validation = new SetValidation();
//                HSSFCell cell;
                HSSFRow hssfRow = hssfSheet.createRow(row);
//                for (int i = 0; i < head.length; i++) {
//                       cell =hssfRow.createCell(i);
//                        cell.setCellValue(new HSSFRichTextString(head[i]));
//                        cell.setCellStyle(cellStyle.alignStyle());
//                        validation.setDataValidation(hssfSheet, cell);
//                }
                int cellPlus = 0;
                this.createSignHead(hssfSheet,hssfRow,head,cellPlus);
                return hssfSheet;
        }

        public HSSFSheet createSignHead(HSSFSheet hssfSheet ,HSSFRow hssfRow,String[] head,int cellPlus){
                SetValidation validation = new SetValidation();
                HSSFCell hssfCell;
                for (int i = 0; i < head.length; i++) {
                        hssfCell =hssfRow.createCell(i+cellPlus);
                        hssfCell.setCellValue(new HSSFRichTextString(head[i]));
                        hssfCell.setCellStyle(cellStyle.alignStyle());
                        validation.setDataValidation(hssfSheet, hssfCell);
                }
                return hssfSheet;
        }

        public HSSFSheet createRowHead(HSSFSheet hssfSheet, String[] head,int row,int depSize){
                SetValidation validation = new SetValidation();
                HSSFCell hssfCell;
                HSSFRow hssfRow = hssfSheet.createRow(row);
                int cellPlus = 0;
                for (;depSize>0;depSize--){
                        this.createSignHead(hssfSheet,hssfRow,head,cellPlus);
                        cellPlus = cellPlus+head.length;
                }

                return hssfSheet;
        }
        public HSSFSheet createRow(HSSFSheet hssfSheet,int row,String name,int length,int height){
                CellRangeAddress range;
                SetValidation validation = new SetValidation();
                HSSFRow hssfRow = hssfSheet.createRow(row);
                hssfRow.setHeight((short) height);
                HSSFCell hssfCell;
                hssfCell = hssfRow.createCell(0);

                hssfCell.setCellValue(new HSSFRichTextString(name));
                range = new CellRangeAddress(row, row, 0, length-1);
                hssfSheet.addMergedRegion(range);

                hssfCell.setCellStyle(cellStyle.headStyle());
                validation.setDataValidation(hssfSheet, hssfCell);

                return hssfSheet;
        }
}
